package com.hzdesk.media.koreabatchmatvector.logic.view;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatCheckBox;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.logic.contract.IWifiHotConTract;
import com.hzdesk.media.koreabatchmatvector.logic.persenter.WifiHotPersenter;
import com.hzdesk.media.koreabatchmatvector.utils.HotUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/8/6.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

class WifiHotActivity extends BaseActivity implements IWifiHotConTract.IWifiHotView {


    @BindView(R.id.activity_wifi_hot_iv_back)
    ImageView activityWifiHotIvBack;
    @BindView(R.id.activity_wifi_hot_iv_close)
    ImageView activityWifiHotIvClose;
    @BindView(R.id.activity_wifi_hot_tv_hot_name)
    TextView activityWifiHotTvHotName;
    @BindView(R.id.activity_wifi_hot_et_input_password)
    EditText activityWifiHotEtInputPassword;
    @BindView(R.id.activity_wifi_hot_checbox)
    AppCompatCheckBox activityWifiHotChecbox;
    @BindView(R.id.activity_wifi_hot_tv_save)
    TextView activityWifiHotTvSave;
    @BindView(R.id.activity_wifi_hot_tv_cancel)
    TextView activityWifiHotTvCancel;
    @BindView(R.id.activity_wifi_hot_hot_setting)
    LinearLayout activityWifiHotHotSetting;
    @BindView(R.id.activity_wifi_hot_ll_bg)
    LinearLayout activityWireLlBg;

    private WifiHotPersenter mWifiHotPersenter = new WifiHotPersenter(this);
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wifi_hot);
        ButterKnife.bind(this);
        mWifiHotPersenter.setCheckBoxListening(activityWifiHotChecbox,this);
    }


    @OnClick({R.id.activity_wifi_hot_iv_back, R.id.activity_wifi_hot_iv_close,
            R.id.activity_wifi_hot_tv_save, R.id.activity_wifi_hot_tv_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_wifi_hot_iv_back:                                                    // 点击返回
                mWifiHotPersenter.onClickedBack();
                break;
            case R.id.activity_wifi_hot_iv_close:                                                   // 点击打开热点
                mWifiHotPersenter.onClickedOpen(this);
                break;
            case R.id.activity_wifi_hot_tv_save:                                                    // 点击保存热点设置
                mWifiHotPersenter.onClickedSave(this);
                break;
            case R.id.activity_wifi_hot_tv_cancel:                                                  // 点击取消保存热点设置
                mWifiHotPersenter.onClickedCancel(this);
                break;
        }
    }
    @Override
    protected void onStart() {
        super.onStart();
        final SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        int selector = mSharedPreferences.getInt("item_skin", 0); //todo 名称
        activityWireLlBg.setBackgroundResource(updateBg[selector]);
        mWifiHotPersenter.init(this);
        setName(HotUtils.getApSSIDAndPwd(this,0));
        setInputPassword(HotUtils.getApSSIDAndPwd(this,1));

    }
    @Override
    public void toFinshPage() {
        finish();
    }

    @Override
    public String getName() {
        return activityWifiHotTvHotName.getText().toString().trim();
    }

    @Override
    public void setName(String name) {
        activityWifiHotTvHotName.setText(name);
    }

    @Override
    public void showOpen() {
        activityWifiHotIvClose.setBackgroundResource(R.drawable.video_player_canvas_open);
    }

    @Override
    public void showCloase() {
        activityWifiHotIvClose.setBackgroundResource(R.drawable.video_player_canvas_close);
    }

    @Override
    public String getInputPassword() {
        return activityWifiHotEtInputPassword.getText().toString().trim();
    }

    @Override
    public void setInputPassword(String password) {
        activityWifiHotEtInputPassword.setText(password);
    }

    @Override
    public void showHotSetting() {
        activityWifiHotHotSetting.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideHotSetting() {
        activityWifiHotHotSetting.setVisibility(View.GONE);
    }

    @Override
    public void isOpenEye() {
        activityWifiHotEtInputPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
    }

    @Override
    public void NoOpenEye() {
        activityWifiHotEtInputPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());

    }
}
